home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
CUGUK
/
PC_LIBS
/
C045.ZIP
/
BTREE.ARC
/
BTUTIL.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-05
|
6KB
|
206 lines
#include <bios.h>
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <conio.h>
#include <ctype.h>
#include "cstruct.h"
#include "ctrlkey.h"
#include "globals.h"
static int KbdRead;
char * conststr(int ch, int n)
{
memset(buffer, ch, n);
buffer[n] = '\0';
return (buffer);
}
void gotoxy(int column, int row)
{
inregs.h.ah = 2;
inregs.h.bh = 0;
inregs.h.dh = row - 1;
inregs.h.dl = column - 1;
int86(0x10, &inregs, &outregs);
}
void clearwindow(int ux, int uy, int lx, int ly)
{
inregs.x.ax = 0x0600; /* fcn 6, al = 0 implies blank window */
inregs.h.bh = 0x07; /* normal attribute */
inregs.h.cl = ux - 1; /* for upper left window column */
inregs.h.ch = uy - 1; /* for upper left window row */
inregs.h.dl = lx - 1; /* for lower right window column */
inregs.h.dh = ly - 1; /* for lower right window row */
int86(0x10, &inregs, &outregs);
}
void beep(void)
{
int i;
for (i = 1; i <= 2; i++) {
sound(784); delay(70); nosound();
sound(587); delay(70); nosound();
}
}
int select(char * prompt, char * charset)
{
char ch;
gotoxy(1, 23); printf("%s", prompt); clreol();
if (strlen(charset) == 0)
return (NULL);
ch = getch();
while (strchr(charset, ch) == NULL) {
beep();
ch = getch();
}
return (ch);
}
int getkey(void)
/* Uses the BIOS to read the next keyboard character */
{
int key, lo, hi;
key = bioskey(KbdRead);
lo = key & 0x00ff;
hi = (key & 0xff00) >> 8;
if (lo == 0 || lo == 0xe0)
return (hi + 0x100);
else
return (lo);
} /* getkey */
char inputstr(char * chp, int lngth, int x, int y, char * chrset)
{
unsigned i, p, custlen, ch;
gotoxy(x, y);
chp[lngth] = '\0';
printf("%s%s", chp, conststr('_', lngth - strlen(chp)));
p = 0;
do {
gotoxy(x+p, y);
ch = getkey();
if (isprint(ch)) {
for (i = lngth-1; i >= p+1; i--)
chp[i] = chp[i-1];
chp[p] = ch;
printf("%s", &chp[p]);
if (p < lngth-1) p++;
}
else switch (ch) {
case RIGHT:
case CTLD : if (p < strlen(chp)-1) p++;
else beep(); break;
case LEFT :
case CTLS : if (p > 0) p--;
else beep(); break;
case CTLLFT:
case CTLA : p = 0; break;
case CTLRGT:
case CTLF : if ((custlen = strlen(chp)) < lngth)
p = custlen;
else
p = custlen-1;
break;
case DELETE :
case CTLG : custlen = strlen(chp);
for (i = p; i <= custlen-1; i++)
chp[i] = chp[i+1];
printf("%s_", &chp[p]);
break;
case CTLH : if (p > 0) {
custlen = strlen(chp);
for (i = p-1; i <= custlen-1; i++)
chp[i] = chp[i+1];
printf("%c%s_", '\x08', &chp[p-1]);
p--;
}
break;
case CTLDEL :
case CTLY : printf("%s", conststr('_', strlen(chp)-p));
chp[p] = '\0';
break;
default : break;
}
} while (!strchr(chrset, ch));
clearwindow (x + strlen(chp), y, x + lngth - 1, y);
return (ch);
}
void outform(void)
{
gotoxy( 1, 5); printf("%12s", "Code :");
gotoxy(30, 5); printf("Date :");
gotoxy( 1, 7); printf("%12s", "First name :");
gotoxy(30, 7); printf("Last name :");
gotoxy( 1, 9); printf("%12s", "Company :");
gotoxy( 1, 10); printf("%12s", "Address 1 :");
gotoxy( 1, 11); printf("%12s", "Address 2 :");
gotoxy( 1, 13); printf("%12s", "Phone :");
gotoxy(30, 13); printf("Extension :");
gotoxy( 1, 15); printf("%12s", "Remarks 1 :");
gotoxy( 1, 16); printf("%12s", "Remarks 2 :");
gotoxy( 1, 17); printf("%12s", "Remarks 3 :");
}
void clearform(void)
{
clearwindow (14, 5, 28, 5);
clearwindow (37, 5, 80, 5);
clearwindow (14, 7, 28, 7);
clearwindow (42, 7, 80, 7);
clearwindow (14, 9, 80, 9);
clearwindow (14,10, 80,10);
clearwindow (14,11, 80,11);
clearwindow (14,13, 28,13);
clearwindow (42,13, 80,13);
clearwindow (14,15, 80,15);
clearwindow (14,16, 80,16);
clearwindow (14,17, 80,17);
}
void initkeyboard()
{
KbdRead = get_kbd() ? 0x10 : 0x00;
}
static int get_kbd()
{
char saved;
int status;
int chk_kbd_bios();
if ((status = chk_kbd_bios()) != 0) { /* if system rom support the */
saved = peekb(0, 0x417); /* enhanced keyboard, it must */
pokeb(0, 0x417, 0x70); /* pass status check test twice.*/
status = chk_kbd_bios();
pokeb(0, 0x417, saved);
}
return (status);
}
static int chk_kbd_bios()
{
union REGS regs;
regs.x.ax = 0x1200;
int86 (0x16, ®s, ®s);
return ( (regs.h.al == peekb(0, 0x417)) ? 1 : 0 );
}